<template>
  <div class="container">
    <div class="nav">
      <router-link to="/my">
        <img src="../../assets/icon/common-left.png" alt="" class="back">
      </router-link>
      <p class="title">提幣</p>
      <img src="../../assets/icon/file.png" alt="" class="rili">
    </div>
    <div class="box">
      <div class="start">
        <p style="margin-left: 10px">選擇幣種</p>
        <select name="" id="" v-model="currency">
          <option value="btc">BTC账户</option>
          <option value="usdt">USDT账户</option>
          <option value="eth">ETH账户</option>
        </select>
      </div>
      <div class="end">
        <p>可用資產</p>
        <p class="usd">{{myMoney}}</p>
      </div>
    </div>
    <div class="num">
      <p class="pleaseNum">提現數量</p>
      <div class="formNum">
        <input type="text" placeholder="請輸入提現數量" v-model="amount" >
        <p style="margin-left: 10px;font-size: 18px;color: #26a2ff" @click="allMoney">全部</p>
      </div>
      <div class="have">
        <p>最小提幣數量:<span ref="tyNum">0.005</span> <span ref="tyOne">BTC</span></p>
        <p>手續費(2%): <span ref="sxf">0.00000</span> <span ref="tyTwo">BTC</span></p>
        <p>到賬數量:<span ref="dz">0.00000</span> <span ref="tyThree">BTC</span></p>
      </div>
    </div>
    <div class="content">
      <div class="content-top">提幣簽約地址</div>
      <div class="content-bottom">
        <textarea style="background:AliceBlue" placeholder="null" rows="5" cols="52" class="address">
        </textarea>
      </div>
    </div>
    <mt-button type="primary" style="width: 342px;height: 40px;margin:16px 13px 10px 13px;letter-spacing: 1.5px
" @click="tb">確認提幣</mt-button>
    <div class="ts">
      <div>
        <p><img src="../../assets/icon/coin/USDT.png" alt="" class="notice"></p>
        <p><img src="../../assets/icon/coin/USDT.png" alt="" class="notice"></p>
      </div>
      <div>
        <p>爲了賬戶安全,請先簽約,再進行提幣</p>
        <p>提交提幣申請後,訂單可以在資金流水中進行查看審核進度24小時内完成審核進度，審核通過后資產
        將在整個網絡節點確認後到達提現賬戶</p>
      </div>


    </div>
  </div>
</template>

<script>
  import {Button, MessageBox} from 'mint-ui';
  import {withDraw} from "../../api/withDraw";
  import Vue from 'vue';
  Vue.component(Button.name, Button);
  export default {
    name: "index",
    data(){
        return {
            currency:'btc',
            userInfo:{},
            drawData:{},
            amount:'',
            myMoney:Number(0).toFixed(8)
        }
     },
     methods:{
         allMoney(){
             this.amount=this.myMoney
         },
        // 提现

            tb(){
             switch (this.currency) {
                 case 'btc':
                     if (this.amount=='' || this.amount<0.005){
                         MessageBox.alert('提现数量至少0.005 BTC')
                     };
                     break;
                 case 'usdt':
                     if (this.amount=='' || this.amount<300){
                         MessageBox.alert('提现数量至少300 USDT')
                     };
                     break;
                 case 'eth':
                     if (this.amount=='' || this.amount<1.5){
                         MessageBox.alert('提现数量至少0.005 BTC')
                     };
             }


                  withDraw({
                     currency: this.currency,
                     amount:this.amount,
                     type: 1,
                     uid :this.userInfo.uid
                  }).then((data)=>{
                      if (data.errorCode==0){
                          MessageBox.alert(data.msg).then(action=>{
                              this.amount='';
                              $(".address").innerText=''
                          })
                      }else {
                          MessageBox.alert(data.msg)
                      }
                  })

            }
     },
      mounted() {
          if (!window.localStorage.getItem('userInfo')) {
              this.$router.push({path:'/'})
          }else {
              this.userInfo=JSON.parse(window.localStorage.getItem('userInfo'));

          }

      },

      watch:{
          amount:{
              handler(newVal){
                  let num=Number(newVal);
              this.$refs.sxf.innerText=(num*0.02).toFixed(5);
                  this.$refs.dz.innerText=(num*0.98).toFixed(5);
              },
              deep: true
          },

          currency:{
              handler(newVal){
                  switch (newVal) {
                      case 'btc':
                         this.$refs.tyOne.innerText='BTC';
                         this.$refs.tyTwo.innerText='BTC';
                         this.$refs.tyThree.innerText='BTC';
                         this.$refs.tyNum.innerText=0.005;
                         break;
                      case 'usdt':
                          this.$refs.tyOne.innerText='USDT';
                          this.$refs.tyTwo.innerText='USDT';
                          this.$refs.tyThree.innerText='USDT';
                          this.$refs.tyNum.innerText=300;
                          break;
                      case 'eth':
                          this.$refs.tyOne.innerText='ETH';
                          this.$refs.tyTwo.innerText='ETH';
                          this.$refs.tyThree.innerText='ETH';
                          this.$refs.tyNum.innerText=1.5;
                          break;


                  }
              }
          }
      }
  }
</script>

<style scoped lang="scss">
  .container {
    width: 100%;
  }

  .nav {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    height: 40px;
    font-size: 17x;
    font-weight: bold;

    .back {
      margin-left: 17.5px;
      width: 16px;
      height: 16px;
    }

    .rili {
      margin-right: 17.5px;
      width: 20px;
      height: 20px;
    }
  }

  .box {
    border-radius: 5px;
    margin: 10px auto;
    width: 355.2px;
    height: 150px;
    display: flex;
    flex-direction: column;
    align-items: center;

    p {
      font-size: 13px;
    }

    .start {
      display: flex;
      flex-direction: row;
      width: 100%;
      height: 50px;
      align-items: center;

      select {
        margin-left: 30px;
        width: 200px;
        height: 50px;
        font-size: 15px;
        border: none;
        font-weight: bold;
      }
    }

    .end {
      display: flex;
      flex-direction: column;
      width: 97%;
      height: 90px;
      background-color: #26a2ff;
      color: #eeeeee;
      align-items: center;
      margin-top: 10px;

      p {
        margin-top: 10px;
      }

      .usd {
        font-size: 18px;
      }
    }
  }

  .num {
    .pleaseNum {
      width: 355.2px;
      margin-left: 8px;
      font-weight: bold;
      height: 28px;
      line-height: 28px;
    }

    width: 355.2px;
    height: 142px;
    margin: 0 auto;

    .formNum {
      margin-bottom: 15px;
      display: flex;
      flex-direction: row;
      align-items: center;

      input {
        border-radius: 5px;
        padding: 5px 5px 5px 10px;
        border: none;
        border-bottom: 1px solid #26a2ff;
        width: 268.2px;
        height: 34px;
        font-size: 14px;
        margin-left: 6px;
      }

      p {
        font-size: 15px;
      }
    }

  }

  .have {
    font-size: 12px;
    margin-left: 9px;
    margin-top: -7px;

    p {
      margin-top: 2px;
    }
  }

  .content {
    width: 100%;
    height: 120px;
  }

  .content-top {
    width: 80%;
    margin-left: 4%;
    font-size: 14px;
    height: 24px;
    line-height: 24px;
  }

  .content-bottom {
    margin-left: 4%;
    font-size: 12px;
  }

  .ts {
   margin-left: 4%;
    display: flex;
    flex-direction: row;
    width: 330px;
    height: 45px;
    font-size: 14px;

    img {
      margin-top: 2px;
      margin-right: 2px;
      height: 14px;
      width: 14px;
    }

  }
</style>
